#include "App.hpp"

namespace SparseCoding
{
	const double App::STEP = 1.0;
	const double App::ISTA_STEP = 0.1;
	const double App::NOISE_VARIANCE = 0.1;
	const std::string App::IMAGES_FILE = "images.txt";
	const std::string App::IMAGE_PREFIX = "image";
	const cv::Size App::VISUALIZATION_SIZE = cv::Size(350, 350);

	App::App()
	{

	}

	int App::Execute()
	{
		std::vector<cv::Mat> images;
		cv::FileStorage imagesFile(IMAGES_FILE, cv::FileStorage::READ);

		for (unsigned int i = 0; i < IMAGE_COUNT; i++)
		{
			std::ostringstream fileNameStream;
			fileNameStream << IMAGE_PREFIX << i;

			cv::Mat currentImage;
			imagesFile[fileNameStream.str()] >> currentImage;

			images.push_back(currentImage);
		}

		DictionaryLearner sparseCoding(images, BASIS_FUNCTION_COUNT, PATCH_SIZE, SAMPLE_COUNT);
		sparseCoding.visualizationInterpolation = cv::INTER_AREA;
		sparseCoding.visualizationSize = VISUALIZATION_SIZE;
		sparseCoding.SetParameters(STEP, ISTA_STEP, NOISE_VARIANCE);

		sparseCoding.Train(ITERATION_COUNT);
		sparseCoding.SaveDictionary();
		sparseCoding.SaveVisualization(VISUALIZATION_SIZE, cv::INTER_AREA);

		return EXIT_S;
	}
}
